package l744.GuanDao;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

public abstract class GuanDaoObject {

    protected int width;
    protected int height;
    protected int x;
    protected int y;
    protected int speed;

    public GuanDaoObject(int width,int height,int x){//鸟
        this.width = width;
        this.height = height;
        this.x=x;
        speed=1;
    }
    public GuanDaoObject(int width,int height){//管道
        this.width = width;
        this.height = height;
        x = 1300;//管道生成X轴坐标
        Random rand = new Random();
        y = rand.nextInt(244)-315;//随机的管道起始高度
        speed =3;//管道间距
    }
    public boolean isHit(GuanDaoObject other){//this代表鸟，other代表管道
        return (this.x>=other.x-this.width+20&&this.x<=other.x
                && this.y<=other.y+347)
                ||(this.x>=other.x-this.width+20&&this.x<=other.x
                &&this.y>=other.y+454);
    }
    public abstract ImageIcon getImages();
    public abstract void move();
    public void paintImage(Graphics g){
            this.getImages().paintIcon(null,g,this.x,this.y);
    }
}
